<template>
  <el-dialog :title="item.title" :visible.sync="visible" :before-close="close" width="500px">
    <el-form :model="form" ref="form" @submit.native.prevent>
      <el-form-item prop="content" label="">
        <el-input
          type="textarea"
          v-model.trim="form.content"
          rows="5"
          placeholder="请输入评论内容"
        ></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="success" @click="save" icon="el-icon-check">发布评论</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    props: {
      item: {
        type: Object,
      },
    },
    components: {},
    data() {
      return {
        visible: true,
        form: {
          content: '',
        },
      };
    },
    mounted() {},
    methods: {
      save() {
        if (!this.form.content.length) return;
        const { parentId, subjectId, subjectType } = this.item;
        this.$service
          .CommentQuickPublish({
            content: this.form.content,
            parentId,
            subjectId,
            subjectType,
          })
          .then((res) => {
            this.$message.success('已回复');
            this.$emit('close'); // 自定义方法
            this.$emit('success'); // 自定义方法
          })
          .catch((err) => {});
      },
      close() {
        this.visible = false; // 隐藏元素
        this.$emit('close'); // 自定义方法
      },
    },
  };
</script>

<style lang="less" scoped></style>
